$(function(){
    $("header .left").mouseover(function(){
        $(".dizhi").show();
        $(this).mouseout(function(){
            $(".dizhi").hide();
           
        })
    })
    $("#xiangxi li").hover(function(){
        $(this).children("a").toggleClass("active").siblings().removeClass("active")
    });
       

    //我的订单
    $(".top-jd").mouseover(function(){
        $(".mejd").show();
        $(this).mouseout(function(){
            $(".mejd").hide();
          
        })
    })
    
    // $("#xiangxi li").hover(function(){
    //     $(this).children("a").toggleClass("active").siblings().removeClass("active")
    // });

    $(".top-qycg").mouseover(function(){
        $(".qycg").show();
        $(this).mouseout(function(){
            $(".qycg").hide();
          
        })
    })
      
    
    //商家服务
    $(".top-sjfw").mouseover(function(){
        $(".sjfw").show();
        $(this).mouseout(function(){
            $(".sjfw").hide();
         
        })
    })
    //网站导航
    $(".top-wzdh").mouseover(function(){
        $(".wzdh").show();
        $(this).mouseout(function(){
            $(".wzdh").hide();
          
        })
    })
    //手机京东
    $(".top-sjjd").mouseover(function(){
        $(".sjjd").show();
        $(this).mouseout(function(){
            $(".sjjd").hide();
         
        })
    })

    //顶部字体颜色
$("header  li").hover(function(){
    $(this).children("a").toggleClass("top-red")
})


//log变化
$(".nav-logo").mouseover(function(){
    $(".logof").hide().siblings().show();
    $(this).mouseout(function(){
        $(".logof").show().siblings().hide();
    })
})

// 滚动条

$(window).on("scroll",function(){
  $currentY=document.documentElement.scrollTop||document.body.scrollTop;
  if($currentY>300){
    // $window.innerHeight=0;
  $(".search").css({
    "position": "fixed",
   "top":0,
   "margin-top": "0px",
   "z-index" : 2,
   "border":"2px solid red",
  },2000)

  // console.log($(".search").offset());
}else{
  $(".search").css({
    "position": "relative",
   "top":0,
   "margin-top": "10px",
   "z-index" : 0,
   "border":"0px solid red",

  })
}
})

// 商品列表变色开始
  $(".feed-bt").hover(function(){
    $(this).children(".tab_li1").children("span").toggleClass("span_red").siblings().removeClass("span_red")
   
    $(this).children(".tab_lit2").toggleClass("lit2_red").siblings().removeClass("lit2_red")

  })
  // 渲染开始
$.get("http://jx.xuzhixiang.top/ap/api/allproductlist.php", {
  uid: 139443,
}).then((resData) => {
let str = ""
for(let i=0;i<resData.data.length;i++) {
  console.log(resData.data[i]); /* 商品详细数据 */
  str+=`
  <li class="title_s" >
 
    <div class="title-img"><img src="${resData.data[i].pimg}" alt="" /></div>
    <div class="title-p" pid="${resData.data[i].pid}">
      <p>
        ${resData.data[i].pname}
      </p>
      <div class="move-pz"><i>￥</i><span>${resData.data[i].pprice}</span></div>
    </div>
 
</li>`
  
}
$(".aside_titles").html(str)
// 渲染结束


  // 点击商品跳转详情页开始
$(".aside_titles>li").on("click", function () {
  // 获取到商品id
 
 let pid =$(this).children(".title-p").attr("pid")
 console.log(pid);
  window.location.href = "detailed.html?id=" + pid;
 

//   $.get("http://jx.xuzhixiang.top/ap/api/detail.php",{
//   id:$(this).children(".title-p").attr("pid")
// }).then((shuju)=>{

//   // 获取到点击商品详细数据
  
//   // window.location.href = "detailed.html";
//   // console.log(shuju);
//   // // let uid = resData.data.id;
//   // localStorage.setItem("uid", uid);
//   // console.log(uid);
// })
 })
   // 点击商品跳转详情页结束


   
// 用户购物车添加商品开始
// let uid = localStorage.getItem(`uid`)
// console.log(uid);
// $(".aside_titles>li").on("click", function(){
//        // http://jx.xuzhixiang.top/ap/api/add-product.php
//       //  http://jx.xuzhixiang.top/ap/api/add-product.php
//   $.get("http://jx.xuzhixiang.top/ap/api/add-product.php",{
//     // uid:139443,
//     uid:uid,
//     pid:$(this).children(".title-p").attr("pid"),
//     pnum:1,
//   }).then((datalist)=>{
//     console.log(datalist);
//   })

// })

//用户购物车添加商品结束

});


// 商品列表变色结束


//点击我的购物车跳转购物列表
let uid =localStorage.getItem("uid");
$(".cart").on("click", function () {
  location.reload();
  location.href = "list.html";
  // console.log("ok");
  // 购物车显示商品数量

})
$.get("http://jx.xuzhixiang.top/ap/api/cart-list.php",{
  id:uid
}).then((fanhui)=>{
  console.log(fanhui.data.length);
  $(".yuand").children("a").text(fanhui.data.length)
})




// console.log();


})

// 轮播图bufen
let obox = document.querySelector(".art-box");
let list = obox.children[0].children;
// let list = document.querySelector["li"];
let i = 0;
let aBtns = document.querySelector(".btns").children;

let Ol = document.querySelector(".ollist").children;
function move() {
  i++;
  // 123
  if (i == list.length) {
    i = 0;
  }
  //321
  if (i == -1) {
    i = list.length - 1;
  }

  for (let j = 0; j < Ol.length; j++) {
    Ol[j].className = "";
  }
  Ol[i].className = "hover";
  for (let j = 0; j < list.length; j++) {
    // list[j].style.opacity = 0;
    startMove(list[j], { opacity: 0 });
  }
  startMove(list[i], { opacity: 100 });
}

// 定时器
let item = setInterval(function () {
  move();
}, 3000);

//右箭头
aBtns[1].onclick = function () {
  move();
};
// 左箭头
aBtns[0].onclick = function () {
  i -= 2;
  move();
};
// 小圆点移入
for (let j = 0; j < Ol.length; j++) {
  Ol[j].onmouseover = function () {
    i = j - 1;
    move();
  };
}

// 移入块   定时开关关闭
obox.onmouseover = function () {
  clearInterval(item);
};

// 移出块  定时开关开启
obox.onmouseout = function () {
  item = setInterval(function () {
    move();
  }, 3000);
};


// 第二轮播图开始
var swiper1 = new Swiper ('#swiper1',{
  navigation: {
    nextEl: '.swiper-button-next',
    prevEl: '.swiper-button-prev',
  },
loop: true,
autoplay:true,
autoplay: {
  delay: 3000,//1秒切换一次
},
}
)

var swiper2 = new Swiper ('#swiper2',{
  navigation: {
    nextEl: '.swiper-button-next',
    prevEl: '.swiper-button-prev',
  },
loop: true,
autoplay:true,
autoplay: {
  delay: 3000,//1秒切换一次
},
controller:{
  control: [swiper1, swiper3],//控制Swiper1和Swiper2
},
}
)
swiper2.controller.control = [swiper1, swiper3]


var swiper3 = new Swiper ('#swiper3',{
  navigation: {
    nextEl: '.swiper-button-next',
    prevEl: '.swiper-button-prev',
  },
loop: true,
autoplay:true,
autoplay: {
  delay: 3000,//1秒切换一次
},
}
)



// 第二轮播图结束
// 切换图开始
var swiper4 = new Swiper("#swiper4", {
  // direction: "vertical", // 垂直切换选项
  loop: true, // 循环模式选项

  // 如果需要分页器
  pagination: {
    el: ".swiper-pagination",
  },

  // 如果需要前进后退按钮
  navigation: {
    nextEl: ".swiper-button-next",
    prevEl: ".swiper-button-prev",
  },
  slidesPerView: 4,
  slidesPerGroup: 4,
  autoplay: {
  delay: 5000,//1秒切换一次
  },
 
  // 如果需要滚动条
  // scrollbar: {
  //   el: ".swiper-scrollbar",
  // },
});


// -----------------------------
// 秒杀倒计时
function timeDown(endTime) {
  let nowTime = new Date(); //开始时间
  let endTimer = new Date(endTime); //结束时间
  let totalS = parseInt((endTimer - nowTime) / 1000); //总的秒数
  let Days = parseInt(totalS / (60 * 60 * 24)); //天数
  let mol = totalS % (60 * 60 * 24); //取余数
  let Hours = parseInt(mol / (60 * 60));
  if (Hours < 10) {
    Hours = "0" + Hours;
  }
  mol = mol % (60 * 60);
  let Minutes = parseInt(mol / 60); //分钟
  if (Minutes < 10) {
    Minutes = "0" + Minutes;
  }
  let Seconds = mol % 60;
  if (Seconds < 10) {
    Seconds = "0" + Seconds;
  }
  let id = document.getElementById("timer");
  let span = document.querySelector(".timeDown").children; //获取span
  span[0].innerHTML = Hours;
  span[1].innerHTML = Minutes;
  span[2].innerHTML = Seconds;
  setInterval(function () {
    timeDown(endTime);
  }, 1000);
}
timeDown("2022-9-9 22:00:00");

//切换图结束
// 购物列表渲染开始

// 购物列表渲染结束

